#coding:utf-8
import os
from common.koufuApi import KoufuApi
from common.koufuShop20Api import KoufuShop20Api
from common.tool import Tools

__author__ = 'yangxianming'

from common.KoufuConf import KoufuConf
from common.picAddress import PicAddress
import json
import requests

'''
手动发送邮件，生产环境
需要手动登陆生产生成复制下JSESSIONID到下面的header中，才能运行
需要从钉钉复制 供应商名
'''

def case():
    #初始化必要的参数
    kou_fu_conf = KoufuConf()
    test_url = kou_fu_conf.shop20_domain_prod
    kou_fu_shop_api = KoufuShop20Api()
    script_name = os.path.basename(__file__)
    tool = Tools
    tf = True
    test_result = ""

    ##登陆
    kou_fu_conf.koufu_shop_headers = {
        "Accept":"application/json, text/javascript, */*; q=0.01",
        "Content-Type":"application/json",
        "Cookie": "JSESSIONID=cd77fb7b-c899-4d0b-99be-d384d70960c2"
    }


    ##获取供应商名字列表
    p = kou_fu_shop_api.get_syssupplier_list(update_body={"name":"集第供应商"})
    r = requests.get(test_url+kou_fu_shop_api.get_syssupplier_list(get_path=1), p, headers=kou_fu_conf.koufu_shop_headers)
    # print("这个是接口api_goods_product_list返回的全部参数\n", r.json())
    supplier_id = r.json()["page"]["list"][0]["id"]
    print(supplier_id)

    ##编辑定时任务
    p = kou_fu_shop_api.get_sys_schedule_update(update_body={"params":supplier_id})
    r = requests.post(test_url+kou_fu_shop_api.get_sys_schedule_update(get_path=1), json.dumps(p), headers=kou_fu_conf.koufu_shop_headers)
    # print("这个是接口api_goods_product_list返回的全部参数\n", r.json())
    print(r.json())

    ##执行定时任务
    p = kou_fu_shop_api.get_sys_schedule_run()
    r = requests.post(test_url+kou_fu_shop_api.get_sys_schedule_run(get_path=1),  json.dumps(p), headers=kou_fu_conf.koufu_shop_headers)
    print(r.json())



    #定义预期描述
    print(str(tf))
    # print(test_result)
    expect_result = "返回参数ebuyCode是否是空"

    #返回测试结果 第一个参数:True or False    第二个参数测试结果描述
    return tf, [test_result, expect_result]

case()